﻿<?php
// Database connection settings
define("PG_DB" , "DATN");
define("PG_HOST", "localhost");
define("PG_USER", "postgres");
define("PG_PORT", "5432");
define("TABLE", "DNHotel");
define("PG_PASS","123456789"); 


$name=addslashes($_GET['name']);
$where = "";
//echo $name;
if(strcmp($name, "") != 0)
	$where="name ilike '%".$name."%'";

$district=addslashes($_GET['district']);
//echo $district;
if(strcmp($district, "0") != 0)
	if(strcmp($name, "") != 0)
		$where=$where." and district ilike '".$district."'";
	else 
		$where=$where." district ilike '".$district."'";

//$sql="SELECT * FROM \"".TABLE."\" WHERE ".$where;
$sql="SELECT *,st_x(ST_Centroid(the_geom)) as x, st_y(ST_Centroid(the_geom)) as y FROM \"".TABLE."\" WHERE ".$where;
$dbcon = pg_connect("dbname=".PG_DB." password=".PG_PASS." host=".PG_HOST." user=".PG_USER);
$query = pg_query($dbcon,$sql);
//echo $sql;
echo "<table border=\"1\">";
echo "<tr>
<th width=\"250\">Tên</th>
<th width=\"400\">Địa chỉ</th>
<th width=\"200\">Vị trí</th>

</tr>";

// <td>", "<a href='map1.php?zoom=6&lat=".$kq['y']."&lon=".$kq['x']."'>Link</a>","</td>
while($kq=pg_fetch_assoc($query)) {
//echo $kq[ten_phuong];
echo "<tr>
<td>", $kq['name'],"</td>
<td>", $kq['address'],"</td>
<td>", "<a href='#' onClick=\"javascript:jump(".$kq['y'].", ".$kq['x']."); return false;\">Link</a>","</td>


</tr>";
}
echo"</table>";
pg_close($dbcon);

?>